
#include <BLabel>
#include <BGridLayout>
#include <BVBoxLayout>
#include <BHBoxLayout>

#include "ConfigDialog.h"

ConfigDialog::ConfigDialog(BWidget* parent) : BDialog(parent)
{
	this->setBorder(3);

	BLabel* inputDeviceLabel = new BLabel("Audio Input");
	_inputDeviceComboBox = new BComboBox();

	BLabel* outputDeviceLabel = new BLabel("Audio Output");
	_outputDeviceComboBox = new BComboBox();

	BLabel* channelsLabel = new BLabel("Channels");
	_channelsComboBox = new BComboBox();
	_channelsComboBox->addItem("Signle Channel", 1);
	_channelsComboBox->addItem("Double Channels", 2);

	BLabel* formatLabel = new BLabel("sample format");
	_formatComboBox = new BComboBox();
	_formatComboBox->addItem("unsigned char", Format_UChar);
	_formatComboBox->addItem("unsinged short", Format_UShort);
	_formatComboBox->addItem("unsigned long", Format_UInt);

	BLabel* samplesPerSecondLabel = new BLabel("samples per second");
	_sampleRateSpinBox = new BSpinBox();

	BGridLayout* gridLayout = new BGridLayout(this);
	gridLayout->setWidget(0, 0, channelsLabel);
	gridLayout->setWidget(0, 1, _channelsComboBox);
	gridLayout->setWidget(1, 0, formatLabel);
	gridLayout->setWidget(1, 1, _formatComboBox);
	gridLayout->setWidget(2, 0, samplesPerSecondLabel);
	gridLayout->setWidget(2, 1, _sampleRateSpinBox);
	gridLayout->setWidget(3, 0, inputDeviceLabel);
	gridLayout->setWidget(3, 1, _inputDeviceComboBox);
	gridLayout->setWidget(4, 0, outputDeviceLabel);
	gridLayout->setWidget(4, 1, _outputDeviceComboBox);

	_okButton = new BButton("OK");
	_cancelButton = new BButton("Cancel");

	BHBoxLayout* bottomLayout = new BHBoxLayout();
	bottomLayout->addSpring();
	bottomLayout->addWidget(_okButton);
	bottomLayout->addWidget(_cancelButton);
	this->setLayout(bottomLayout, Part_Bottom);

	BStringList deviceNames;
	int count = BAudioInput::DeviceNames(deviceNames);
	for (int i = 0; i < deviceNames.size(); i++)
	{
		const BString& name = deviceNames[i];
		_inputDeviceComboBox->addItem(name);
	}

	count = BAudioOutput::DeviceNames(deviceNames);
	for (int i = 0; i < deviceNames.size(); i++)
	{
		const BString& name = deviceNames[i];
		_outputDeviceComboBox->addItem(name);
	}

	connect(_formatComboBox, Signal_CurrentChanged, &ConfigDialog::slotFormatChanged);
	connect(_sampleRateSpinBox, Signal_ValueEdited, &ConfigDialog::slotSampleRateEdited);
	connect(_channelsComboBox, Signal_CurrentChanged, &ConfigDialog::slotChannelCountChanged);
}
ConfigDialog::~ConfigDialog()
{

}

void ConfigDialog::init(BAudioInput* audioInput, BAudioOutput* audioOutput)
{
	_audioInput = audioInput;
	_audioOutput = audioOutput;
	_formatComboBox->setText(audioInput->sampleRate());
	_sampleRateSpinBox->setValue(audioInput->sampleRate());
	_channelsComboBox->setValue(audioInput->channelCount());
}

void ConfigDialog::slotFormatChanged(int current)
{

}
void ConfigDialog::slotSampleRateEdited(int value)
{

}
void ConfigDialog::slotChannelCountChanged(int channels)
{

}

